package com.woniu.woniuticket.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.woniuticket.common.Result;
import com.woniu.woniuticket.entity.Seat;
import com.woniu.woniuticket.service.ISeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author spirit
 * @since 2020-01-02
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/woniuticket/seat")
public class SeatController {

    @Autowired
    private ISeatService iss;

    //进入选座界面获取座位表及信息
    @RequestMapping("/getallseat")
    public String getAllSeat(Integer movieHallId,Integer showSessionId){
        System.out.println(movieHallId+"~~~"+showSessionId);
        String result = iss.getAllSeat(movieHallId,showSessionId);
        System.out.println("座位分布："+result);
        return result;
    }


    //pc端首页进入获取影厅
    @RequestMapping("/getinformation")
    public Result getInformation(Integer schoolId){
        System.out.println("学校id："+schoolId);
        List<Seat> result = iss.getInformation(schoolId);
        System.out.println("影厅："+result.toString());
        return Result.success(result);
    }

    //pc端对影厅进行修改
    @RequestMapping("/updateseatpc")
    public Result updateSeat(Integer sid,Integer mid,String seat ){
        QueryWrapper<Seat> qw = new QueryWrapper<>();
        qw.eq("movie_hall_id",mid).eq("school_id",sid);
        Seat seat1 = new Seat();
        seat1.setSeatNum(seat).setMovieHallId(mid).setSchoolId(sid);
        Boolean result = iss.update(seat1,qw);
        return Result.success(result);
    }

    //pc端新增影厅座位
    @RequestMapping("/insertseatpc")
    public Result insertSeat(Integer x,Integer y,Integer m,Integer sid){
        System.out.println("新增的影厅："+x+y+m+sid);
        String str ="";
        for(int i = 0;i < x;i++){
            for(int j = 0 ; j < y;j++){
                str+=1;
            }
            str+=",";
        }
        String newSeat = str.substring(0,str.length()-1);
        System.out.println(newSeat);
        Seat seat = new Seat();
        seat.setSeatNum(newSeat);
        seat.setSchoolId(sid);
        seat.setMovieHallId(m);
        seat.setSeatStatus(m+"号厅");
        System.out.println(seat.toString());
        Boolean result = iss.save(seat);
        System.out.println(result);
        return Result.success(result);
    }
}

